package com.echoplots.shardingjdbc.strage;

import java.util.Collection;

import org.apache.shardingsphere.api.sharding.hint.HintShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.hint.HintShardingValue;

import com.echoplots.shardingjdbc.pojo.Order;
import com.google.common.collect.Sets;

public class OrderDataBaseHintAlgorithm implements HintShardingAlgorithm<Order> {

	@Override
	public Collection<String> doSharding(Collection<String> arg0, HintShardingValue<Order> arg1) {
		
		Collection<String> databaseSet = Sets.newConcurrentHashSet();
		Collection<Order> values = arg1.getValues();
		for(Order order:values){
			databaseSet.add("pay"+order.getMerchant());
		}
		//TODO 根据传进来的分片值 路由到对应的物理库
		return databaseSet;
	}

}
